package gamefw.tests.implementations.game;

import gamefw.gameplugin.AbstractGameLogic;
import gamefw.gameplugin.AbstractPlayer;
import gamefw.gameplugin.GameBoard;
import gamefw.gameplugin.GameEntity;
import gamefw.gameplugin.IGameAbstractFactory;
import gamefw.gameplugin.IGameResourceProperties;

public class SimpleGameFactory implements IGameAbstractFactory {
	
	/* The following fields are used to tune some of the objects created in order
	 * to provide different tests
	 */
	
	// used to set the number of players that the game logic will return
	private int numPlayers = 2;
	
	// used to set the number of loops that the created game logic will do
	private int maxLoops = 0;
	
	// used to set if IGameResourceProperties objects will return true or false
	// when queried for compatibility with a visual resource type 
	private boolean resourcePropToReturn = true;
	
	// When true, players created will be null
	private boolean createNullPlayer = false;
	
	// When true, entities created will be null
	private boolean createNullEntity = false;

	@Override
	public IGameResourceProperties createGameResourceProperties() {
		return new SimpleGameResourceProperties(this.resourcePropToReturn);
	}

	@Override
	public AbstractGameLogic createGameLogic() {
		return new SimpleGameLogic(this.numPlayers, this.maxLoops);
	}

	@Override
	public GameBoard createGameBoard() {
		return new SimpleGameBoard();
	}

	@Override
	public AbstractPlayer createPlayer(boolean isHuman) {
		if (this.createNullPlayer) {
			return null;
		}
		return new SimplePlayer();
	}

	@Override
	public GameEntity[] createGameEntities(String[] entityNames) {
		SimpleGameEntity ge = new SimpleGameEntity();
		GameEntity[] list = {ge};
		return list;
	}

	@Override
	public GameEntity createGameEntity(String entityName) {
		if (this.createNullEntity) {
			return null;
		}
		return new SimpleGameEntity();
	}

	public void setNumPlayers(int numPlayers) {
		this.numPlayers = numPlayers;
	}

	public int getNumPlayers() {
		return numPlayers;
	}

	public void setMaxLoops(int maxLoops) {
		this.maxLoops = maxLoops;
	}

	public int getMaxLoops() {
		return maxLoops;
	}

	public void setResourcePropToReturn(boolean resourcePropToReturn) {
		this.resourcePropToReturn = resourcePropToReturn;
	}

	public boolean isResourcePropToReturn() {
		return resourcePropToReturn;
	}

	public void setCreateNullPlayer() {
		this.createNullPlayer = true;
	}
	
	public void setCreateNullEntity() {
		this.createNullEntity = true;
	}

}
